package cn.lysj.framework.common.security;

import cn.lysj.framework.common.CommonConstant;
import cn.lysj.framework.common.security.jwt.CurrentCustomerMethodArgumentResolver;
import cn.lysj.framework.common.security.jwt.CurrentUserMethodArgumentResolver;
import cn.lysj.framework.common.validate.ValidatorResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * @author zk
 * @date 2018-08-14 4:01
 * @Description 配置参数解析器
 */
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resource/**").addResourceLocations(CommonConstant.BASE_LOCAL_RESOURCE_DIR_CONFIG);
        super.addResourceHandlers(registry);
    }



    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(currentUserMethodArgumentResolver());
        argumentResolvers.add(validatorArgumentResolvers());
        argumentResolvers.add(currentCustomerMethodArgumentResolver());
        super.addArgumentResolvers(argumentResolvers);
    }

    @Bean
    public CurrentCustomerMethodArgumentResolver currentCustomerMethodArgumentResolver() {
        return new CurrentCustomerMethodArgumentResolver();
    }

    @Bean
    public CurrentUserMethodArgumentResolver currentUserMethodArgumentResolver() {
        return new CurrentUserMethodArgumentResolver();
    }

    @Bean
    public ValidatorResolver validatorArgumentResolvers() {
        return new ValidatorResolver();
    }
}
